<template>
   <div>
         <GlobalCardBox  title="系统消息" :showDown="SETSYSTEMINFO" :contontStyle="SystemInfoStyle">
            <div slot="content" id="content" >
                
                <!-- 头部 -->
                <div class="head flex">
                    <button v-for="(item,index) in naviData" :key="index" class="naviOne" 
                           
                             :class="getNaviClass(item.value)" @click="changeNavi(item.value)">{{item.label}}</button>
                </div>

                <div class="content" v-if="getNewInfoData?.length > 0">
                   <div v-if="naviIndex == 1" class="report flex">
                         <div v-for="item in getNewInfoData" :key="item.id" class="dataOne flex">
                            <img :src="item.createdCover" >
                            <div class="detail">
                                <p class="overflow">举报文章:{{item.title }}</p>
                                <p  class="overflow">举报类型:{{item.classify | reportType }}</p>
                                <p  class="overflow">举报时间:{{item.createdTime | time}}</p>
                                <p  class="overflow"  :style="getResStyle(item.reportState)">举报结果:{{item.reportState | process('举报')}}</p>
                            </div>
                             
                         </div>
                   </div>
                    <div v-else class="appeal flex">
                         <div v-for="item in getNewInfoData" :key="item.id" class="dataOne flex">
                            <img :src="item.createdCover" >
                            <div class="detail">
                                <p  class="overflow">申诉文章:{{item.title }}</p>
                                <p  class="overflow" v-if="item.appealType == 1">申诉类型:解封文章</p>
                                <p  class="overflow" v-else>申诉类型:恢复文章</p>
                                <p  class="overflow">申诉时间:{{item.createdTime | time}}</p>
                                <p  class="overflow" :style="getResStyle(item.appealState)">申诉结果:{{item.appealState | process('申诉')}}</p>
                            </div>

                            <div class="BaseFunBox flex" v-if="item.appealState != 0">
                                 <div class="BaseFun flex">
                                       <div class="fun flex delete" @click="beforeDelete(item)">
                                          <i class="el-icon-delete"></i>
                                       </div>
                                       <div class="fun flex refresh"   @click="renewAppeal(item)" v-if="item.appealState == 2">
                                          <i class="el-icon-refresh-right"></i>
                                       </div>
                                   </div>
                            </div>
                          
                             
                         </div>
                   </div>
                </div>

                  <el-empty v-else class="content"></el-empty>
            </div>
         </GlobalCardBox>
   </div>
</template>
<script>
import GlobalCardBox from '@/components/Package/GlobalCardBox/GlobalCardBox.vue'
import { mapMutations, mapState } from 'vuex'
import request from '@/axios'
  export default 
  {
  components: { GlobalCardBox },
     name :'',
     computed:{
        ...mapState('Login',['User']),
        getNewInfoData(){
           if(this.InfoData == null) return []
           if(this.naviIndex == 1)
           return this.InfoData.report || []
           else   return this.InfoData.appeal || []
        }
     },
     data() {
        return {
            SystemInfoStyle:{height:'700px'},
            naviIndex:1,
            naviData:[
               {value:1,label:'举报信息'},
               {value:2,label:'申诉信息'},
            ],
            InfoData:null,
        }
     },
     created(){
         this.init()
     },
     methods: {
        ...mapMutations('Report',['SETSYSTEMINFO','SETAPPEAL']),
        getResStyle(state){
            if(state == 0)
            return {color:'#ebb563'}
            if(state == 1) return {color:'#67C23A'}
            return {color:'#F56C6C'}
        },
        async init(){
           let uid = this.User?.uid 
           let res = await request.get('/api/report/get',{params:{uid}})
           if(res.data.code != 200)
              return this.$message.error(res.data.message)
           this.InfoData = res?.data?.data || null
        },
        getNaviClass(index){
           if(index == this.naviIndex)
           return 'active'
        },
        changeNavi(index){
           this.naviIndex = index
        },
        renewAppeal(appeal){
            let title = '申述恢复文章 ' + appeal?.title
            let appealInfo =  this.appeal?.appealType == 1 ? '解除文章限制' : '恢复文章'
            let newAppeal = {
                createdUid:this.User?.uid || 0 ,
                appealType:this.appeal?.appealType || 1 ,
                articleId:appeal?.articleId || 0 ,
                username:this.User?.username,
                title:appeal?.title,
                appealInfo

            }
             this.SETAPPEAL({title,state:true,appeal:newAppeal})
             this.SETSYSTEMINFO()
        },
        beforeDelete(appeal){
            this.$confirm('此操作将永久删除该申诉记录, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
               }).then(() => {
                     this.deleteAppeal(appeal)
               },()=>{})
        },
        async deleteAppeal(appeal){
            let res = await request.post("/api/appeal/delete",appeal)
            if(res.data.code == 200){
               this.$message.success(res.data.message)
                 let appeals =  this.InfoData?.appeal
               appeals = appeals?.filter(item => item.id != appeal.id)
               this.InfoData.appeal = appeals || []
               return
            }
            if(res?.data?.code  == -1) {
                this.loginOut()
                return this.$public.toLogin()
            }
            this.$message.error(res.data.message)

        }
     },
  }
</script>
<style scoped lang='less'>
.head{
  width: 100%;
  background: none;
  justify-content: space-around;

  .naviOne{
     font-size: 18px;
     margin: 5px;
     padding: 5px;
     border-radius: 5px;
     
  }
  .active , .naviOne:hover{
        background: var(--GeneralBackColor);
        color: white;
  }

}

.content{
   width: 100%;
   height: 550px;
   max-height: calc( 90vh - 150px);
   margin-top: 10px;
}
.report,.appeal{
   width: 100%;
   justify-content: flex-start;
}
.dataOne{
   width: calc( 50% - 10px ) ;
   min-width: 200px;
   background: var(--BackColor);
   padding: 20px;
   box-sizing: border-box;
   border-radius: 5px;
   margin: 5px;
   position: relative;
   overflow: hidden;

   &:hover{
      .BaseFunBox{
         display: flex;
      }
   }

   img{
      width: 30%;
      height: 100px;
      margin-right: 10px;
   }

   .BaseFunBox{
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      position:absolute;
      top: 0;
      left: 0;
      display: none;
   }
  .BaseFun{
     width: 100%;
     justify-content: center;

     .fun{
       background: var(--BackColor);
       border-radius: 5px;
       width: 40px;
       height: 40px;
       margin-right: 20px;
       padding: 5px;
       color: white;
       border-radius: 50%;

       i{
          font-size: 20px;
       }

     }
      .delete{
          background: red;
     }
     .refresh{
        background: dodgerblue;
     }
       
  }
   .detail{
      width: calc( 70% - 10px);
     

      p{
         width: 100%;
         font-size: 15px;
          margin-bottom: 5px;
      }
   }
}
</style>

